#!/bin/bash
#everything is set I know where I go now.
echo "Hashing Local files for later comparison";
cd $LOCALDIR
list_of_files=$(mktemp);
find . -type f | grep -v $METADATA_DIR > $list_of_files #no need to hash the metadata
#sed is to remove double slashes for safety, probably not needed
hash_dest=$(echo ${LOCALDIR}/${METADATA_DIR}/${NEWESTHASHFILE} | sed 's/\/\//\//g')
if [ -e $hash_dest ] ; then rm $hash_dest; fi
OLDIFS=$IFS;
IFS="
";
cat $list_of_files | while read filename ; do
    #only replace the _FIRST_ instance of a double space, so files that have a double space are fine
    sha256sum $filename | sed 's/\ \ /\t/' >>  $hash_dest
done
IFS=$OLDIFS;
rm $list_of_files
